package com.neusoft.bizcore.web.dto.result;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;

import io.swagger.annotations.ApiModelProperty;
import lombok.ToString;

/**
 * description
 *
 * @author sunchf
 * @date 2018年12月10日 上午9:36:31
 */
@ToString
public class ResultDTO<T> extends AbstractResultDTO {

    private static final long serialVersionUID = -7771443524171954099L;

    /**
     * business data object
     */
    @ApiModelProperty(value = "business data object", position = 1)
    private T data;

    @JsonInclude(JsonInclude.Include.NON_NULL)
    @JsonProperty(value = "data", index = 2)
    public T getData() {
        return this.data;
    }

    private void setData(final T data) {
        this.data = data;
    }

    public ResultDTO() {
    }

    ResultDTO(final Status status) {
        this.status = status;
    }

    public static ResultDTO<Void> success() {
        final ResultDTO<Void> result = new ResultDTO<>(Status.success);
        return result;
    }

    public static ResultDTO<Void> failure() {
        final ResultDTO<Void> result = new ResultDTO<>(Status.failure);
        return result;
    }

    public static <T> ResultDTO<T> success(final T data) {
        final ResultDTO<T> result = new ResultDTO<>(Status.success);
        result.setData(data);
        return result;
    }

    public static <T> ResultDTO<T> failure(final T data) {
        final ResultDTO<T> result = new ResultDTO<>(Status.failure);
        result.setData(data);
        return result;
    }
}
